package com.crane.oss.web.controller.school;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.crane.common.core.dto.MultiResponse;
import com.crane.common.core.dto.Response;
import com.crane.common.core.dto.SingleResponse;
import com.crane.oss.school.bean.request.QueryCourseSetReq;
import com.crane.oss.school.bean.request.courseset.AddCourseSetReq;
import com.crane.oss.school.bean.request.courseset.UpdateCourseSetReq;
import com.crane.oss.school.bean.resp.CourseSetResp;
import com.crane.oss.school.service.CourseSetService;
import com.crane.oss.web.BaseBusinessController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * @author zhenxing.pi
 * @email ccsu123456@qq.com
 * @date 2022年03月26日 14时24分54秒
 */

@Api(value = "CourseSetController", tags = {"目标开课信息设置"})
@RestController
@RequestMapping("/school/courseSet")
public class CourseSetController extends BaseBusinessController {

    @Autowired
    CourseSetService courseSetService;


    @ApiOperation(value = "获取列表信息", notes = "获取列表信息")
    @ApiImplicitParam(name = "request", value = "请求对象", required = true, dataType = "QueryCourseSetReq")
//    @RequiresPermissions("school:courseset:list")
    @PostMapping("/list")
    public MultiResponse<CourseSetResp> list(@RequestBody QueryCourseSetReq request) {
        request.setPartyId(getPartyId());
        IPage<CourseSetResp> page = courseSetService.queryList(request);
        return MultiResponse.of(page.getRecords(), (int) page.getTotal(), request);
    }


    @ApiOperation(value = "获取详细信息", notes = "获取详细信息")
    @ApiImplicitParam(name = "id", value = "请求对象", paramType = "path", dataType = "Long")
//    @RequiresPermissions("school:courseset:info")
    @GetMapping("/info/{id}")
    public SingleResponse<CourseSetResp> info(@PathVariable("id") Long id) {
        CourseSetResp courseSetResp = courseSetService.queryCourseSet(id);
        return SingleResponse.of(courseSetResp);
    }


    @ApiOperation(value = "新增", notes = "获取新增信息")
    @ApiImplicitParam(name = "request", value = "请求对象", required = true, dataType = "AddCourseSetReq")
//    @RequiresPermissions("school:courseset:save")
    @PostMapping("/save")
    public Response save(@RequestBody @Valid AddCourseSetReq request) {
        request.setPartyId(getPartyId());
        request.setCreateUserId(getUserId());
        int count = courseSetService.save(request);
        return Response.buildSuccess();
    }

    @ApiOperation(value = "修改", notes = "修改")
    @ApiImplicitParam(name = "request", value = "请求对象", required = true, dataType = "UpdateCourseSetReq")
//    @RequiresPermissions("school:courseset:update")
    @PostMapping("/update")
    public Response update(@RequestBody @Valid UpdateCourseSetReq request) {
        request.setPartyId(getPartyId());
        request.setUpdateUserId(getUserId());
        int count = courseSetService.update(request);
        return Response.buildSuccess();
    }


}
